<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="http://localhost/YouHuoShop/Static/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="http://localhost/YouHuoShop/Static/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="http://localhost/YouHuoShop/Static/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="http://localhost/YouHuoShop/Static/Admin/Flat/img/favicon.ico">
	    <script type="text/javascript" src="http://localhost/YouHuoShop/Static/uploadify/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="http://localhost/YouHuoShop/Static/uploadify/jquery.uploadify.min.js"></script>	
	    <link href="http://localhost/YouHuoShop/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
	    <script type="text/javascript" charset="utf-8" src="http://localhost/YouHuoShop/Static/ueditor1_4_3/ueditor.config.js"></script>
	    <script type="text/javascript" charset="utf-8" src="http://localhost/YouHuoShop/Static/ueditor1_4_3/ueditor.all.min.js"></script>
	    <script type="text/javascript" charset="utf-8" src="http://localhost/YouHuoShop/Static/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	    <script type="text/javascript">
	    	var getAttrURL='<?php echo U("AjaxGetAttr");?>';
	    	var cid=<?php echo $goodsData['category_cid'];?>;
	    	var bid=<?php echo $goodsData['brand_bid'];?>;
	    </script>
	    <script src="http://localhost/YouHuoShop/Static/Admin/js/goods.js" type="text/javascript" charset="utf-8"></script>
	    <script src="http://localhost/YouHuoShop/Static/Admin/js/editgoods.js" type="text/javascript" charset="utf-8"></script>
	    <style type="text/css">
	    	.addPrice{
	    		text-align: right;
	    	}
	    	.imgList ul li{
	    		list-style: none;
	    		float:left;
	    	}
	    	.imgList img{
	    		margin-right: 30px;
	    		margin-bottom: 20px;
	    	}
	    </style>
	</head>
	<body>
		<form action="" method="post">
		<div class="alert alert-success">编辑商品</div>
		<!-- 基本信息 -->
		<table class="table table-hover">
			<tr class="active">
			  <th width="150">基本信息</th>
			  <th></th>
			  <th width="450"></th>
			</tr>
			<tr>
				<td style="line-height:40px">商品名称</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="gname" value="<?php echo $goodsData['gname'];?>" id="" class="form-control" type="text" placeholder="请输入商品名称" required="" >
				</td>
				<td></td>
			</tr>
			<tr >
				<td style="line-height:40px">所属分类</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<select name="category_cid" id='category' class="form-control">
						<!--<option value="<?php echo $goodsData['category_cid'];?>" checked tpid=<?php echo $goodsData['tpid'];?>><?php echo $goodsData['cname'];?></option>-->
						<option value="0">请选择</option>
						<?php foreach ($cateData as $k=>$c){?>
							<option value="<?php echo $c['cid'];?>" tpid='<?php echo $c['tpid'];?>'><?php echo $c['_name'];?></option>
						<?php }?>
					</select>
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">所属品牌</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<select name="brand_bid" id="brand" class="form-control">
						<option value="0">请选择</option>
						<?php foreach ($brandData as $k=>$b){?> 
							<option value="<?php echo $b['bid'];?>"><?php echo $b['bname'];?></option>
						<?php }?>	
					</select>
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">商品标号</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="gnum"  value="<?php echo $goodsData['gnum'];?>" class="form-control" type="text" placeholder="请输入商品标号： " required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">单位</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="unit" value="<?php echo $goodsData['unit'];?>" class="form-control" type="text" placeholder="请输入单位名称： 如 ( 件 ) " required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">市价场</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="market_price" value="<?php echo $goodsData['market_price'];?>" class="form-control" type="text" placeholder="请输入市价场" required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">商城价</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="shop_price" value="<?php echo $goodsData['shop_price'];?>" class="form-control" type="text" placeholder="请输入商城价" required="">
				</td>
				<td></td>
			</tr>
			<tr>
				<td style="line-height:40px">点击量</td>
				<td style="padding-top:13px;padding-bottom:13px;">
					<input name="click_num" value="<?php echo $goodsData['click_num'];?>" class="form-control" type="text" placeholder="商品点击量" required="">
				</td>
				<td></td>
			</tr>
		</table>
		<!-- 商品属性 -->
		<table id="goodsAttr" class="table table-hover">
			<tr class="active">
			   <th width="150">商品属性</th>
			   <th></th>
			   <th width="450"></th>
			</tr>
			<?php foreach ($attr as $k=>$a){?>
				<tr>
					<td style="line-height:40px"><?php echo $a['tp_aname'];?></td>
					<td>
						<select name="attr[<?php echo $a['tp_aid'];?>]" class="form-control">
							<option value="0">请选择</option>
							<?php foreach ($a['tp_avalue'] as $kk=>$av){?>
								<option value="<?php echo $av;?>"     <?php if(in_array($av,$goodsAttr)){ ?>selected<?php } ?>><?php echo $av;?></option>
							<?php }?>
						</select>
					</td>
					<td></td>
				</tr>
			<?php }?>
		</table>
		<!-- 商品规格 -->
		<table id="goodsSpec" class="table table-hover">
			<tr class="active">
			  <th width="80">商品规格</th>
			  <th width="200"></th>
			  <th width="80"></th>
			  <th width="100"></th>
			  <th width="30"></th>
			</tr>
			<?php foreach ($spec as $k=>$s){?>
				<!--判断属性表中的属性值是空还是数组，输出不同的表单-->
				    <?php if($s['tp_avalue']==''){ ?>
				<!--单行文本添加式-->
					<!--循环出旧的数据-->
					    <?php if(isset($goodsSpec[$s['tp_aid']])){ ?>
						<?php $time=1; ?>
						<?php foreach ($goodsSpec[$s['tp_aid']] as $gk=>$gs){?>
							<tr class="attrList">
								<td style="line-height:40px"><?php echo $s['tp_aname'];?></td>
								<td>
									<input name="spec[<?php echo $s['tp_aid'];?>][]" value="<?php echo $gs['attr_value'];?>" class="form-control" placeholder="请输入<?php echo $s['tp_aname'];?>" type="text">
								</td>
								<td class="addPrice" style="line-height:40px;">附加价格</td>
								<td>
									<input class="form-control" placeholder="请输入附加价格" name="addPrice[<?php echo $s['tp_aid'];?>][]" value="<?php echo $gs['subjoin'];?>" type="text">
								</td>
								<td>
									    <?php if($time==1){ ?>
										<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
									<?php }else{ ?>
										<a href="javascript:;" class="btn btn-danger removeSpec">删除规格 </a>
									<?php } ?>
									<?php $time++; ?>
								</td>
							</tr>
						<?php }?>
					<?php }else{ ?>
						<tr class="attrList">
							<td style="line-height:40px"><?php echo $s['tp_aname'];?></td>
							<td>
								<input name="spec[<?php echo $s['tp_aid'];?>][]" value="" class="form-control" placeholder="请输入<?php echo $s['tp_aname'];?>" type="text">
							</td>
							<td class="addPrice" style="line-height:40px;">附加价格</td>
							<td>
								<input class="form-control" placeholder="请输入附加价格" name="addPrice[<?php echo $s['tp_aid'];?>][]" value="0" type="text">
							</td>
							<td>
								<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
							</td>
						</tr>
					<?php } ?>
				<!--下拉菜单式-->
				<?php }else if(is_array($s)){ ?>
					<!--循环出旧的数据-->
					    <?php if(isset($goodsSpec[$s['tp_aid']])){ ?>
						<?php $time=1; ?>
						<?php foreach ($goodsSpec[$s['tp_aid']] as $gk=>$gs){?>
							<tr class="attrList">
								<td style="line-height:40px"><?php echo $s['tp_aname'];?></td>
								<td>
									<select name="spec[<?php echo $s['tp_aid'];?>][]" class="form-control">
										<option value="0">请选择</option>
										<?php foreach ($s[tp_avalue] as $kk=>$av){?>
											<option     <?php if($av==$gs['attr_value']){ ?>selected<?php } ?> value="<?php echo $av;?>"><?php echo $av;?></option>
										<?php }?>
									</select>
								</td>
								<td class="addPrice" style="line-height:40px;">附加价格</td>
								<td>
									<input class="form-control" placeholder="请输入附加价格" name="addPrice[<?php echo $s['tp_aid'];?>][]" value="<?php echo $gs['subjoin'];?>" type="text">
								</td>
								<td>
									    <?php if($time==1){ ?>
										<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
									<?php }else{ ?>
										<a href="javascript:;" class="btn btn-danger removeSpec">删除规格 </a>
									<?php } ?>
									<?php $time++; ?>
								</td>
							</tr>
						<?php }?>
					<?php }else{ ?>
						<tr class="attrList">
							<td style="line-height:40px"><?php echo $s['tp_aname'];?></td>
							<td>
								<select name="spec[<?php echo $s['tp_aid'];?>][]" class="form-control">
									<option value="0">请选择</option>
									<?php foreach ($s[tp_avalue] as $kk=>$av){?>
										<option value="<?php echo $av;?>"><?php echo $av;?></option>
									<?php }?>
								</select>
							</td>
							<td class="addPrice" style="line-height:40px;">附加价格</td>
							<td>
								<input class="form-control" placeholder="请输入附加价格" name="addPrice[<?php echo $s['tp_aid'];?>][]" value="0" type="text">
							</td>
							<td>
								<a href="javascript:;" class="btn btn-primary addSpec">添加规格 </a>
							</td>
						</tr>
					<?php } ?>
				<?php } ?>
			<?php }?>
		</table>
		<!-- 列表图 -->
		<table class="table table-hover">
			<tr class="active">
				<th width="110">列表图</th>
				<th width="300"></th>
				<th width="600"></th>
			</tr>
			<tr>
				<td style="line-height:40px">上传列表图</td>
				<td>
					<input id="list_img_btn" class="upbtn" type="file" multiple="false">
					<label for="">类型: *.jpg,*.png 大小: 2000KB</label>
				</td>
				<td>
	            	<div id="listImgList" class="imgList"><ul>
	            		    <?php if($goodsData['list_img']){ ?>
		            		<li>
		            			<img src="http://localhost/YouHuoShop/<?php echo $goodsData['list_img'];?>" alt="" style="width:200px;height:100px;" />
		            	 		<input type="hidden" name="list_img" value="<?php echo $goodsData['list_img'];?>" />
		            		</li>
	            		<?php } ?>
	            	</ul></div>
				</td>
			</tr>
		</table>
		<!-- 商品图册 -->
		<table class="table table-hover">
			<tr class="active">
			  <th width="110">商品图册</th>
				<th width="300"></th>
				<th width="600"></th>
			</tr>
			<tr>
				<td style="line-height:40px">上传商品图册</td>
				<td>
					<input id="showImg_btn" class="upbtn" type="file" multiple="true">
					<label for="">类型: *.jpg,*.png 大小: 2000KB</label>
				</td>
				<td>
	            	 <div id="showImgList" class="imgList"><ul>
	            	 	<?php foreach ($goodsData['bimg'] as $k=>$v){?>
	            	 		<li>
		            	 		<img src="http://localhost/YouHuoShop/<?php echo $v;?>" alt="" style="width:200px;height:100px;" />
		            	 		<input type="hidden" name="showImg[]" value="<?php echo $v;?>" />
	            	 		</li>
	            	 	<?php }?>
	            	 </ul></div>
				</td>
			</tr>
		</table>
		<!-- 商品详细 -->
		<table class="table table-hover">
			<tr class="active">
			  <th class="goodsDetails">商品详细</th>
			</tr>
			<tr class="bdtext">
				<td>
					<script id="editor" type="text/plain" name="info" style="width:1024px;height:500px;"><?php echo $goodsData['info'];?></script>
	   				 <script>
	       				 var ue = UE.getEditor('editor');
	   				 </script>
				</td>
			</tr>
		</table>
		<!-- 售后服务 -->
		<!--<table class="table table-hover">
			<tr class="active">
			  <th >售后服务</th>
			</tr>
			<tr>
				<td style="line-height:40px">百度编辑器</td>
			</tr>
		</table>-->
		<input type="hidden" name="gid" value="<?php echo $hd['get']['gid'];?>" />
		<input class="btn btn-primary btn-block" type="submit" value="确定修改">
		</form>
		
		<!--商品列表图上传-->
		<div lab="uploadFile">
	        <script type="text/javascript">
	            $(function() {
	                $('#list_img_btn').uploadify({
	                    'formData'     : {//POST数据
	                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                    },
	                    'fileTypeDesc' : '上传文件',//上传描述
	                    'fileTypeExts' : '<?php echo $set['filetype'];?>',
	                    'swf'      : 'http://localhost/YouHuoShop/Static/uploadify/uploadify.swf',
	                    'uploader' : '<?php echo U("listImg");?>',
	                    'buttonText':'选择文件',
	                    'fileSizeLimit' : '2000KB',
	                    'uploadLimit' : 1,//上传文件数
	                    'width':65,
	                    'height':25,
	                    'successTimeout':10,//等待服务器响应时间
	                    'removeTimeout' : 0.2,//成功显示时间
	                    'onUploadSuccess' : function(file, data, response) {
	                        data=$.parseJSON(data);
	                        var imageUrl = data.image?data.url:'http://localhost/YouHuoShop/Static/image/default.png';
	                        var li="<li><img src='"+imageUrl+"' style='width:200px;height:100px;'/>"+
	                      		  "<input type='hidden' name='list_img' value='"+data.path+"'/> </li>";
	                        $("#listImgList ul").prepend(li);
	                        $('#list_img_btn').slideUp().siblings('label').slideUp();
	                    }
	                });
//	                alert($("#listImgList ul").find('img').length!=0);
	                if($("#listImgList ul").find('img').length!=0){
	                	$('#list_img_btn').css({"display":"none"}).siblings().css({"display":"none"})
	                };
	            });
	           
	        </script>
		</div>
		<!--商品图册上传-->
		<div lab="uploadFile">
	        <script type="text/javascript">
	            $(function() {
	                $('#showImg_btn').uploadify({
	                    'formData'     : {//POST数据
	                        '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                    },
	                    'fileTypeDesc' : '上传文件',//上传描述
	                    'fileTypeExts' : '<?php echo $set['filetype'];?>',
	                    'swf'      : 'http://localhost/YouHuoShop/Static/uploadify/uploadify.swf',
	                    'uploader' : '<?php echo U("showImg");?>',
	                    'buttonText':'选择文件',
	                    'fileSizeLimit' : '2000KB',
	                    'uploadLimit' : 10,//上传文件数
	                    'width':65,
	                    'height':25,
	                    'successTimeout':10,//等待服务器响应时间
	                    'removeTimeout' : 0.2,//成功显示时间
	                    'onUploadSuccess' : function(file, data, response) {
	                        data=$.parseJSON(data);
	                        var imageUrl = data.image?data.url:'http://localhost/YouHuoShop/Static/image/default.png';
	                        var li="<li><img src='"+imageUrl+"' style='width:200px;height:100px;'/>"+
	                      		  "<input type='hidden' name='showImg[]' value='"+data.path+"'/> </li>";
	                        $("#showImgList ul").prepend(li);
	                    }
	                });
	            });
	        </script>
		</div>
	
	</body>
</html>
